package com.kaka.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kaka.pojo.SysLog;
import com.kaka.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/syslog")
public class SysLogController {

    @Autowired
    private SysLogService sysLogService;

    /*@RequestMapping("/findAll")
    public String findAll(@RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
                          @RequestParam(value = "limit", defaultValue = "10", required = false) Integer limit,
                          HttpServletRequest request) {
        PageHelper.startPage(page, limit);
        List<SysLog> all = sysLogService.findAll();
        PageInfo<SysLog> pageInfo = new PageInfo<>(all);
        request.setAttribute("pageInfo", pageInfo);
        return "/syslog/syslog-list.jsp";
    }*/

    @RequestMapping("/findAll")
    public String findLike(@RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
                           @RequestParam(value = "limit", defaultValue = "10", required = false) Integer limit,
                           @RequestParam(value = "username", defaultValue = "", required = false) String username,
                           @RequestParam(value = "url", defaultValue = "", required = false) String url,
                           @RequestParam(value = "executionTime", defaultValue = "0", required = false) Long executionTime,
                           HttpServletRequest request) {
        PageHelper.startPage(page, limit);
        List<SysLog> all = sysLogService.findLike(username, url, executionTime);
        PageInfo<SysLog> pageInfo = new PageInfo<>(all);
        request.setAttribute("pageInfo", pageInfo);
        request.setAttribute("username",username);
        request.setAttribute("url",url);
        request.setAttribute("executionTime",executionTime);
        return "/syslog/syslog-list.jsp";
    }
}
